jQuery(function($) {

		
			var code = drawPic();
			document.getElementById("vcode_img").onclick = function(e) {
				e.preventDefault();
				code = drawPic();
			}
			
	        $("#login").click(function(event) {
				    var uname = $('#uname').val();
					var upwd = $('#upwd').val();
		            var vcode = $('#vcodeId').val();
					if(uname.length == 0) {
						layer.tips("用户名不能为空!", "#uname", {
							tips: [2, "#FF0000"],
							time: 1000,
						});
						return;
					}
					var patrn = /^[a-zA-Z0-9._]{6,12}$/ 
					if(!patrn.exec(upwd)) {
						layer.tips("密码格式错误!", "#upwd", {
							tips: [2, "#FF0000"],
							time: 1000,
						});
						return;
					}
                    var patrn = /^[A-Za-z0-9]{4}$/
		            if(!patrn.exec(vcode)){
		            	layer.tips("验证码输入有误!","#vcodeId",{
		            		tips:2,
		            		time:1000
		            	});
		            	return;
		            }
		            if(vcode.toLowerCase()!= code.toLowerCase()){
		            console.log(vcode,code)
		            	layer.tips("验证码输入错误!","#vcodeId",{
		            		tips:1,
		            		time:1000
		            	});
		            	return;
		            }
				$.ajax({
					url: "js/login.json",
					type: "get",
					dataType: "json",
					success: function(result) {
						var userinfo = result.data;
						var temp=false;
						$.each(userinfo, function(login,value){
							if(uname == value.uname && upwd == value.upwd){
								temp = true;
								return;
							}
						});
						if(temp == false) 
						layer.msg("登录失败！", {
							icon:2,time:2000
						});
						else{
							var state = $("#rememberPassword").prop("checked");
							if(state == true) {
								localStorage.setItem("uname",uname);
								localStorage.setItem("upwd",upwd);
							}else{
								localStorage.clear();
							}
							sessionStorage.setItem("uname",uname);
						location.href = "manager.html";
						}
						
					},
					error: function() {
						layer.msg("请求服务器失败！", {
							icon: 2,
							time: 2000
						});
					}
				});
			});
			$("#register").click(function() {
				location.href = 'http://127.0.0.1:8848/OKAir-layui/html/register.html'
			});
});

function reset(){
	        $("#form_login")[0].reset();
	        
          }

